{extend name="common/dialog" /}
{block name="main"}
<div class="admin-main fadeInUp animated" ng-app="hd" ng-controller="ctrl">
<!--     <div class="padding30">
        <h3 class="page-box-title">{$title}</h3>
    </div> -->
    <div class="layui-form-box dialog-form-box" style="margin-top:25px;">
        <form class="layui-form">
            <input type="hidden" name="id" value="{$row['id']}">
            <div class="layui-form-item">
                <label class="layui-form-label">{:lang('Chinese Name')}</label>
                <div class="layui-input-6" style="">
                   <input type="text" name="name" value="{$row['name']}" lay-verify="required" placeholder="{:lang('Please input area name')}" class="layui-input">
                </div>
                
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">{:lang('English Name')}</label>
                <div class="layui-input-6" style="">
                   <input type="text" name="name_en" value="{$row['name_en']}" lay-verify="required" placeholder="{:lang('Enter English Name')}" class="layui-input">
                </div>
                
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">{:lang('Incon')}</label>
                <div class="layui-input-6" style="position: relative;">
                    <input type="text"  name="icon" placeholder="" value="{$row['icon']}" style=""  id="_icon" class="layui-input" readonly="" >
                    <button type="button" class="layui-btn layui-btn-primary input-upload-btn" title="{:lang('Upload Image')}" id="_mediaBtn" style=""><i class="icon icon-upload3"></i></button>
                </div>
                
            </div>
            <br/>
            <br/>
            <div class="layui-form-item">
                <label class="layui-form-label layui-form-label-no" >&nbsp;</label>
                <div class="layui-input-6 pleft22">
                    <button type="button" class="layui-btn" lay-submit="" lay-filter="submit">{:lang('Submit')}</button>
                </div>
            </div>
        </form>
    </div>
</div>
{/block}
{block name="footer"}
<script>
    var m = angular.module('hd',[]);
    m.controller('ctrl',['$scope',function($scope) {
        //$scope.field = '{$info}'!='null'?{$info}:{name:''};
        layui.use(['form', 'layer','upload'], function () {
            var form = layui.form, layer = layui.layer,$= layui.jquery,upload = layui.upload;
            form.on('submit(submit)', function (data) {
                loading = layer.load(1,{shade:[0.1,'#fff']});
                // 提交到方法 默认为本身
                //data.field.id = $scope.field.id;
                $.post("", data.field, function (res) {
                    layer.close(loading);
                    if (res.code > 0) {
                        layer.msg(res.msg, {time: 1800, icon: 1}, function () {
                            top.location.reload();
                        });
                    } else {
                        layer.msg(res.msg, {time: 1800, icon: 2});
                    }
                });
            })
             //普通图片上传
            var loading = null;
            var uploadInst = upload.render({
                elem: '#_mediaBtn'
                ,url: '{:url("api/upload/expand",array('network_id'=>$row['id']))}'
                ,data:{network_id:1}
                ,before: function(obj){
                    //预读本地文件示例，不支持ie8
                    loading =layer.load(1, {shade: [0.1,'#fff']});
                }
                ,done: function(res){
                    layer.close(loading);  
                    //上传成功
                    if(res.code == 0){
                        $('#_icon').val(res.url);
                    }else{
                        //如果上传失败
                        return layer.msg("{:lang('Upload failure')}");
                    }
                }
                ,error: function(){
                    layer.close(loading);  
                    //演示失败状态，并实现重传
                    return layer.msg("{:lang('Upload failure')}");
                }
            });
        });
    }]);
</script>
{/block}